import * as actions from '../actions/index';

// 对页面prop 数据进行管理
const initialState = {
  commitsPage: 1,
  publicData: null,
  // 库信息
  projectInfo: {},
  // 是否已获取库信息
  isProjectInfoFetched: false,
  // 是否成功创建库
  createRepositorySuccess: false,
  // 引导
  isCodeupGuideFlowActive: false,
  isCodeupGuideSafetyActive: false,
  isCodeupGuideMergeActive: false,
  lastMirrorSyncRecord: {},
  mirrorSyncSetting: {},
  genWatermarkimage: {},
  wikiEnable: false,
};
const defaultAction = {
  type: 'doNothing',
};

export default function index(state = initialState, action = defaultAction) {
  switch (action.type) {
    case actions.UPDATE_DATA:
      return { ...state, ...action.data };
    case actions.UPDATE_COMMITS_PAGE:
      return { ...state, commitsPage: action.data };
    case actions.RECEIVE_DATA:
      return { ...state, publicData: action.data };
    case actions.RECEIVE_PROJECTINFO:
      return { ...state, projectInfo: action.data, isProjectInfoFetched: true };
    case actions.PROJECT_RECEIVE_LAST_MIRROR_RECORD:
      return { ...state, lastMirrorSyncRecord: action.data };
    case actions.RESET_DATA:
      return initialState;
    case actions.SET_IMPORT_STATUS:
      return { ...state, projectInfo: { ...state.projectInfo, import_status: action.data } };
    case actions.RESET_ISPROJECTINFOFETCHED:
      return { ...state, isProjectInfoFetched: false };
    case actions.CODEUP_GUIDE_FLOW:
      return { ...state, isCodeupGuideFlowActive: action.data };
    case actions.CODEUP_GUIDE_SAFETY:
      return { ...state, isCodeupGuideSafetyActive: action.data };
    case actions.CODEUP_GUIDE_MERGE:
      return { ...state, isCodeupGuideMergeActive: action.data };
    case actions.PROJECT_RECEIVE_MiRROR_SETTINGS:
      return { ...state, mirrorSyncSetting: action.data };
    case actions.CODEUP_GEN_WATERMARK_BASE64:
      return { ...state, genWatermarkimage: action.data };
    default:
      return state;
  }
}
